using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace CatalogMigration
{
	/// <summary>
	/// A utility class that logs the migration process.
	/// [Info] Informational log.
	/// [Fail] Error log.
	/// [Pass] process passed log.
	/// </summary>
	public class Tools
	{
		/// <summary>
		/// Default Constructor, it does nothing.
		/// </summary>
		public Tools(){}

		/// <summary>
		/// Log a string value.
		/// </summary>
		/// <param name="entryValue"></param>
		public static void Log(string entryValue)
		{
			Tools.Log(entryValue, "", null);
		}

		/// <summary>
		/// Log exceptions.
		/// </summary>
		/// <param name="entryValue"></param>
		/// <param name="Ex"></param>
		public static void Log(string entryValue, Exception Ex)
		{
			Tools.Log(entryValue, "", Ex);
		}

		public static void Log(string entryValue, string AppendString)
		{
			Tools.Log(entryValue, AppendString, null);
 		} 

		public static void Log(string entryValue, string AppendString, Exception Ex)
		{
			string text1;
			string text2;
			string text3;
			Exception exception1;
			object[] objArray1;
			DateTime time1;
			try
			{
				text1 = "log.txt";
				text2 = "";
				if ((AppendString != "") && (AppendString != string.Empty))
				{
					text2 = string.Concat(": ", AppendString);
				}
				text3 = "";
				if (Ex != null)
				{
					text3 = string.Concat("\n", Ex.Message);
				}
				using (StreamWriter writer1 = new StreamWriter(text1, true, Encoding.Default))
				{
					objArray1 = new object[5];
					time1 = DateTime.Now;
					objArray1[0] = time1.ToLongTimeString();
					time1 = DateTime.Now;
					objArray1[1] = time1.ToLongDateString();
					objArray1[2] = entryValue;
					objArray1[3] = text2;
					objArray1[4] = text3;
					writer1.WriteLine("{0} {1}: {2}{3}{4}", objArray1);
				}
			}
			catch (Exception exception2)
			{
				exception1 = exception2;
				MessageBox.Show(exception1.ToString());
			}
		} 
	}
}
